﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xinkui.Common.Enum;
using CommonFramework.Attach;
using System.IO;
using CommonFramework.Utility;
namespace Xinkui.Common.FileAction
{
    public class FileFactory : FileBase
    {
        /// <summary>
        /// 获取浏览地址
        /// </summary>
        /// <param name="fileArray">文件集合</param>
        /// <returns></returns>
        private static string GetFilePathByFileArray(string fileArray, ESourceType sType)
        {
            if (string.IsNullOrEmpty(fileArray))
            {
                return string.Empty;
            }

            return GetDirectoryPath(fileArray.SplitString(";").FirstOrDefault(), sType);
        }

        /// <summary>
        /// 获取附件浏览地址
        /// </summary>
        /// <param name="fileArray">文件集合</param>
        /// <param name="sType">指定类型</param>
        /// <param name="fileSize">文件尺寸枚举</param>
        /// <returns></returns>
        public static string BrowerFile(string fileArray, ESourceType sType, int width, int height)
        {
            FileSettingEntity fsEntity = FileManger.GetFileSetting((int)sType);
            string strFileSize = width * height > 0 ? (width + "_" + height).ToString() : string.Empty;

            if (string.IsNullOrEmpty(fileArray))
            {
                return string.Empty;
            }

            string fileName = GetFilePathByFileArray(fileArray, sType);

            if (string.IsNullOrEmpty(fileName))
            {
                return string.Empty;
            }

            string filepath = fileName.Replace(Path.GetExtension(fileName), strFileSize + Path.GetExtension(fileName));

            return filepath;
        }

        /// <summary>
        /// 获取附件浏览地址
        /// </summary>
        /// <param name="fileArray">文件集合</param>
        /// <param name="sType">指定类型</param>
        /// <param name="fileSize">文件尺寸枚举</param>
        /// <returns></returns>
        public static string BrowerFile(string fileArray, ESourceType sType)
        {
            FileSettingEntity fsEntity = FileManger.GetFileSetting((int)sType);

            if (string.IsNullOrEmpty(fileArray))
            {
                return string.Empty;
            }

            string fileName = GetFilePathByFileArray(fileArray, sType);

            if (string.IsNullOrEmpty(fileName))
            {
                return string.Empty;
            }
            return fileName;
        }


    }
}
